const { getMenu, setMenu } = require("./sql");
const menuApi = async (ctx) => {
  const url = ctx.request.url;
  const id = +url?.substring(url?.lastIndexOf("/") + 1) || null;
  switch (url) {
    case `/menu/getMenu`:
      const menu = await getMenu();
      return (body = {
        data: menu.results || null,
        code: menu.code,
      });
    case `/menu/setMenu/${id}`:
      console.log(id, ctx.request.body);
      await setMenu(id, ctx.request.body);
      const set = await getMenu();
      return (body = {
        data: set.results || null,
        code: set.code,
      });
    default:
      break;
  }
};
module.exports = { menuApi };
